package com.nuc.kl.module.basedata.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;

import net.sf.json.JSONArray;

import org.apache.struts2.ServletActionContext;
import org.junit.Test;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.nuc.kl.base.BaseAction;
import com.nuc.kl.module.kpoint.entity.KnowledgeCheckData;


@Controller
@Scope("prototype")
public class CheckAction extends BaseAction<KnowledgeCheckData> {

	
	 
	/**
	 * 设置通过率和审核人数
	 * 
	 * @return
	 * @throws Exception
	 */
/*	public String set() throws Exception{
		
		//return 
	}*/
	
	/** 列表页面 */
	public String set() throws Exception {
		
		return "list";
	}
	
	
	/** 列表 */
	public String listJson() throws Exception {

		Properties properties = new Properties();
		//InputStream is = getClass().getResourceAsStream("/knowledgeCheck.properties");
		InputStream is = new FileInputStream(ServletActionContext.getServletContext().getRealPath("/WEB-INF/classes")+File.separator + "knowledgeCheck.properties");
		properties.load(is);	
		is.close();
		
		KnowledgeCheckData checkData = new KnowledgeCheckData();
		
		checkData.setChecknum(Integer.parseInt(properties.get("checknum").toString()));
		checkData.setPassrate(Integer.parseInt(properties.get("passrate").toString()));
		response.getWriter().write(JSONArray.fromObject(checkData).toString());
		
		return null;
	}
	
	@Test
	public String check() throws Exception {
		
		Properties properties = new Properties();
		//InputStream is = getClass().getResourceAsStream("/knowledgeCheck.properties");
		InputStream is = new FileInputStream(ServletActionContext.getServletContext().getRealPath("/WEB-INF/classes")+File.separator + "knowledgeCheck.properties");
		properties.load(is);
		is.close();
		
		//ServletActionContext.getServletContext().getRealPath(arg0)
		
		OutputStream os = new FileOutputStream(ServletActionContext.getServletContext().getRealPath("/WEB-INF/classes")+File.separator + "knowledgeCheck.properties");
		properties.setProperty("checknum", model.getChecknum()+"");
		properties.setProperty("passrate", model.getPassrate()+"");
		properties.store(os, "");
			return null;
		
	}

	// -----------------getter-----------setter---------------------------
	
}
